#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int leap_year(int y) {
	if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
		return 1;
	else
		return 0;
}

void date(int a) {
	switch (a) {
	case 0:
		printf("Sun");
		break;
	case 1:
		printf("Mon");
		break;
	case 2:
		printf("Tue");
		break;
	case 3:
		printf("Wed");
		break;
	case 4:
		printf("Thu");
		break;
	case 5:
		printf("Fri");
		break;
	case 6:
		printf("Sat");
		break;
	}
}

int main() {
	int y, m, d, d1 = 0, d2 = 0, day;
	int month[12] = { 31,0,31,30,31,30,31,31,30,31,30,31 };
	printf("YYYYMMDD:");
	scanf("%4d%2d%2d", &y, &m, &d);
	(leap_year(y)) ? (month[1] = 29) : (month[1] = 28);
	if (m > 12 || m < 1 || d<1 || d>month[m - 1]) {
		printf("invalid date");
		return 0;
	}
	for (int i = 1; i < y; i++) {
		if (leap_year(i))
			d1 += 366;
		else
			d1 += 365;
	}
	for (int j = 0; j < m - 1; j++) {
		d2 += month[j];
	}


	day = d + d1 + d2;
	int x = day % 7;
	date(x);
	return 0;
}